#include "bts_mgmt.h"
#include "ui_bts_mgmt.h"
#include "QSqlDatabase"
#include "QDebug"
#include "QSqlError"
#include "QSqlQuery"
#include "account.h"
#include "register_dialog.h"
#include "QMessageBox"
#include "QVariant"
#include "deposit_info.h"
#include "cust_acc_open_dialog.h"
#include "cust_myaccount_showinfo.h"
#include "clerk_review_acc_open.h"
#include "cust_apply_deposit_dialog.h"
#include "cust_apply_withdraw_dialog.h"
#include "cust_latest_withdraw.h"
#include "cust_acc_lost_apply.h"
#include "clerk_withdraw_apply_info.h"
#include "clerk_manage_withdraw_apply_dialog.h"
#include "transaction_info.h"
#include "manager_my_cust_info.h"
#include "manager_add_clerk_dialog.h"
#include "withdraw_info.h"
#include "QDateTime"

BTS_Mgmt::BTS_Mgmt(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::BTS_Mgmt)
{
    ui->setupUi(this);
    initUi();
    connectSlots();
    initAccountSqlite();
    initDepositInfoSqlite();
    initWithdrawInfoSqlite();
    initTransactionDetailsSqlite();
    //默认的经理
    account acc(2,"老王","123","123");
    acc.insertToDB();
}

//客户切换界面
void BTS_Mgmt::custHandlePageChange(int id)
{
    ui->cust_page_box->setCurrentIndex(id);
    if(id == 0) ui->cust_head_bot_now_page->setText("首页");
    else if(id == 1) ui->cust_head_bot_now_page->setText("个人中心");
    else if(id == 2) ui->cust_head_bot_now_page->setText("存款申请");
    else if(id == 3) ui->cust_head_bot_now_page->setText("取款申请");
    else if(id == 4) ui->cust_head_bot_now_page->setText("交易明细");
}

//营业员切换界面
void BTS_Mgmt::clerkHandlePageChange(int id)
{
    ui->clerk_page_box->setCurrentIndex(id);
    if(id == 0) ui->clerk_head_bot_now_page->setText("首页");
    else if(id == 1) ui->clerk_head_bot_now_page->setText("个人中心");
    else if(id == 2) ui->clerk_head_bot_now_page->setText("我的客户");
    else if(id == 3) ui->clerk_head_bot_now_page->setText("取款管理");
}

//经理切换界面
void BTS_Mgmt::managerHandlePageChange(int id)
{
    ui->manager_page_box->setCurrentIndex(id);
    if(id == 0) ui->manager_head_bot_now_page->setText("客户管理");
    else if(id == 1) ui->manager_head_bot_now_page->setText("营业员管理");
    else if(id == 2) ui->manager_head_bot_now_page->setText("交易明细");
}

//连接槽函数
void BTS_Mgmt::connectSlots()
{
    connect(ui->cust_home,&options::optClicked,this,&BTS_Mgmt::custHandlePageChange);
    connect(ui->cust_center,&options::optClicked,this,&BTS_Mgmt::custHandlePageChange);
    connect(ui->cust_deposit,&options::optClicked,this,&BTS_Mgmt::custHandlePageChange);
    connect(ui->cust_withdrawl,&options::optClicked,this,&BTS_Mgmt::custHandlePageChange);
    connect(ui->cust_transaction_history,&options::optClicked,this,&BTS_Mgmt::custHandlePageChange);

    connect(ui->clerk_home,&options::optClicked,this,&BTS_Mgmt::clerkHandlePageChange);
    connect(ui->clerk_center,&options::optClicked,this,&BTS_Mgmt::clerkHandlePageChange);
    connect(ui->clerk_manage_my_cust,&options::optClicked,this,&BTS_Mgmt::clerkHandlePageChange);
    connect(ui->clerk_manage_withdrawl,&options::optClicked,this,&BTS_Mgmt::clerkHandlePageChange);

    connect(ui->manager_cust,&options::optClicked,this,&BTS_Mgmt::managerHandlePageChange);
    connect(ui->manager_clerk,&options::optClicked,this,&BTS_Mgmt::managerHandlePageChange);
    connect(ui->manager_transaction_history,&options::optClicked,this,&BTS_Mgmt::managerHandlePageChange);

}

//初始化账户数据库
void BTS_Mgmt::initAccountSqlite()
{
    //导入数据库驱动
    QSqlDatabase sqlite = QSqlDatabase::addDatabase("QSQLITE","MY");
    //设置数据库名称
    sqlite.setDatabaseName("accountDB.db");
    //打开数据库
    sqlite.open();

    //创建表
    QString sql1("CREATE TABLE IF NOT EXISTS CUSTOMER(\
                id INTEGER PRIMARY KEY AUTOINCREMENT,\
                username varchar(50) NOT NULL,\
                password varchar(50) NOT NULL,\
                telNumber varchar(50) NOT NULL)");

    QString sql2("CREATE TABLE IF NOT EXISTS CLERK(\
                employeeId INTEGER PRIMARY KEY AUTOINCREMENT,\
                username varchar(50) NOT NULL,\
                password varchar(50) NOT NULL,\
                telNumber varchar(50) NOT NULL)");

    QString sql3("CREATE TABLE IF NOT EXISTS MANAGER(\
                id INTEGER PRIMARY KEY AUTOINCREMENT,\
                username varchar(50) NOT NULL,\
                password varchar(50) NOT NULL,\
                telNumber varchar(50) NOT NULL)");
    QSqlQuery query(sqlite);
    query.exec(sql1);
    query.exec(sql2);
    query.exec(sql3);
}


//初始化存款信息数据库
void BTS_Mgmt::initDepositInfoSqlite()
{
    //导入数据库驱动
    QSqlDatabase sqlite = QSqlDatabase::addDatabase("QSQLITE","deposit");
    //设置数据库名称
    sqlite.setDatabaseName("depositDB.db");
    //打开数据库
    sqlite.open();

    //创建表
    QString sql1("CREATE TABLE IF NOT EXISTS DEPOSIT(\
                id INTEGER PRIMARY KEY AUTOINCREMENT,\
                custtelnumber varchar(50) NOT NULL,\
                custname varchar(50) NOT NULL,\
                custpassword varchar(50) NOT NULL,\
                custaddress varchar(50) NOT NULL,\
                savingstype varchar(50) NOT NULL,\
                savingsamount varchar(50) NOT NULL,\
                savingstime varchar(50) NOT NULL,\
                islost varchar(50) NOT NULL,\
                losttime varchar(50) NOT NULL,\
                clerkname varchar(50) NOT NULL,\
                clerkemployeeid varchar(50) NOT NULL,\
                reviewstatus varchar(50) NOT NULL)");

    QSqlQuery query(sqlite);
    query.exec(sql1);

}

//初始化取款信息数据库
void BTS_Mgmt::initWithdrawInfoSqlite()
{
    //导入数据库驱动
    QSqlDatabase sqlite = QSqlDatabase::addDatabase("QSQLITE","withdraw");
    //设置数据库名称
    sqlite.setDatabaseName("withdrawDB.db");
    //打开数据库
    sqlite.open();
    //创建表
    QString sql1("CREATE TABLE IF NOT EXISTS WITHDRAW(\
                id INTEGER PRIMARY KEY AUTOINCREMENT,\
                custtelnumber varchar(50) NOT NULL,\
                custname varchar(50) NOT NULL,\
                custpassword varchar(50) NOT NULL,\
                custaddress varchar(50) NOT NULL,\
                savingstype varchar(50) NOT NULL,\
                savingsamount varchar(50) NOT NULL,\
                savingstime varchar(50) NOT NULL,\
                islost varchar(50) NOT NULL,\
                losttime varchar(50) NOT NULL,\
                clerkname varchar(50) NOT NULL,\
                clerkemployeeid varchar(50) NOT NULL,\
                withdrawtime varchar(50) NOT NULL,\
                interest varchar(50) NOT NULL,\
                withdrawamount varchar(50) NOT NULL,\
                reviewstatus varchar(50) NOT NULL)");

    QSqlQuery query(sqlite);
    query.exec(sql1);

}

//初始化交易明细数据库
void BTS_Mgmt::initTransactionDetailsSqlite()
{
    //导入数据库驱动
    QSqlDatabase sqlite = QSqlDatabase::addDatabase("QSQLITE","transaction");
    //设置数据库名称
    sqlite.setDatabaseName("transactionDB.db");
    //打开数据库
    sqlite.open();

    //创建表
    QString sql1("CREATE TABLE IF NOT EXISTS TRANS(\
                id INTEGER PRIMARY KEY AUTOINCREMENT,\
                custtelnumber varchar(50) NOT NULL,\
                transactiontype varchar(50) NOT NULL,\
                transactionamount varchar(50) NOT NULL,\
                transactiontime varchar(50) NOT NULL)");

    QSqlQuery query(sqlite);
    query.exec(sql1);
}

//更新客户交易明细界面
void BTS_Mgmt::refreshCustTransactionDetail()
{
    //更新前先删除所有已存在的信息
    // 删除所有已存在的子控件
    QLayoutItem* child;
    while ((child = ui->transaction_detail_box_layout->takeAt(0)) != nullptr)
    {
        // 删除子控件
        if (child->widget())
        {
            delete child->widget();
        }
        // 删除布局项
        delete child;
    }

    //正式更新
    ui->transaction_detail_box_layout->setAlignment(Qt::AlignTop|Qt::AlignLeft);
    QSqlDatabase sqlite_ts = QSqlDatabase::database("transaction");
    QSqlQuery query_ts(sqlite_ts);
    query_ts.prepare("SELECT transactiontype,transactionamount,transactiontime FROM TRANS WHERE custtelnumber = ? ");
    query_ts.addBindValue(ui->telnumber_now->text());
    query_ts.exec();
    while(query_ts.next())
    {
        transaction_info * info = new transaction_info(this);
        info->initTransactionInfo(ui->telnumber_now->text(),query_ts.value(0).toString(),query_ts.value(1).toString(),query_ts.value(2).toString());
        ui->transaction_detail_box_layout->addWidget(info);
    }
}

//更新经理交易明细界面
void BTS_Mgmt::refreshManagerTransactionDetail()
{
    //经理界面无需多次更新，只需初始化一次即可
    //正式更新
    ui->manager_transaction_detail_box_layout->setAlignment(Qt::AlignTop|Qt::AlignLeft);
    QSqlDatabase sqlite_ts = QSqlDatabase::database("transaction");
    QSqlQuery query_ts(sqlite_ts);
    query_ts.prepare("SELECT custtelnumber,transactiontype,transactionamount,transactiontime FROM TRANS ");
    query_ts.exec();
    while(query_ts.next())
    {
        transaction_info * info = new transaction_info(this);
        info->initTransactionInfo(query_ts.value(0).toString(),query_ts.value(1).toString(),query_ts.value(2).toString(),query_ts.value(3).toString());
        ui->manager_transaction_detail_box_layout->addWidget(info);
    }
}

//把交易数据插入交易明细内
void BTS_Mgmt::insertToTransactionDB(const QString &number, const QString &type, const QString &amount, const QString &time)
{
    QSqlDatabase sqlite = QSqlDatabase::database("transaction");
    QSqlQuery query(sqlite);
    query.prepare("INSERT INTO TRANS(custtelnumber,transactiontype,transactionamount,transactiontime)\
           VALUES(?,?,?,?)");
    query.addBindValue(number);
    query.addBindValue(type);
    query.addBindValue(amount);
    query.addBindValue(time);
    query.exec();
}

//初始化经理到期储金界面
void BTS_Mgmt::initManagerCustFinishMoney()
{
    QSqlDatabase sqlite_ts = QSqlDatabase::database("deposit");
    QSqlQuery query_ts(sqlite_ts);
    query_ts.prepare("SELECT savingstype,savingsamount,savingstime FROM DEPOSIT");
    //今天到期的储金数(加利息)
    double today_money = 0.0;
    double tomorrow_money = 0.0;
    double after_tomorrow_money = 0.0;
    query_ts.exec();
    while(query_ts.next())
    {
        QDateTime time1 = QDateTime::fromString(query_ts.value(2).toString());
        QDateTime time2 = QDateTime::currentDateTime();
        qint64 secsDiff = time1.secsTo(time2);
        int daysDiff = secsDiff/86400;
        double money1 = 0.0;
        double money2 = 0.0;
        double money3 = 0.0;
        if(query_ts.value(0) == "1年")
        {
            if(daysDiff == 365)
            {
                (void)daysDiff;
                money1 = query_ts.value(1).toInt() *0.0198 * 1;
            }
            else if(daysDiff == 364)//明天到期则距今天364天
            {
                (void)daysDiff;
                money2 = query_ts.value(1).toInt() *0.0198 * 1;
            }
            else if(daysDiff == 363)//后天到期则距今天363天
            {
                (void)daysDiff;
                money3 = query_ts.value(1).toInt() *0.0198 * 1;
            }
            else continue;
        }
        else if(query_ts.value(0) == "3年")
        {

            if(daysDiff == 1095)
            {
                (void)daysDiff;
                money1 = query_ts.value(1).toInt() *0.0225 * 3;
            }
            else if(daysDiff == 1094)
            {
                (void)daysDiff;
                money2 = query_ts.value(1).toInt() *0.0225 * 3;
            }

            else if(daysDiff == 1093)
            {
                (void)daysDiff;
                money3 = query_ts.value(1).toInt() *0.0225 * 3;
            }
            else continue;
        }
        else
        {
            if(daysDiff == 1825)
            {
                (void)daysDiff;
                money1 = query_ts.value(2).toInt() *0.035 * 5;
            }
            else if(daysDiff == 1824)
            {
                (void)daysDiff;
                money2 = query_ts.value(2).toInt() *0.035 * 5;
            }
            else if(daysDiff == 1823)
            {
                (void)daysDiff;
                money3 = query_ts.value(2).toInt() *0.035 * 5;
            }
            else continue;
        }
        today_money += money1;
        tomorrow_money += money2;
        after_tomorrow_money += money3;
    }
    ui->today_text->setText(QString::number(today_money,'f',2));
    ui->tomorrow_text->setText(QString::number(tomorrow_money,'f',2));
    ui->after_tomorrow_text->setText(QString::number(after_tomorrow_money,'f',2));
}

//初始化最近一次取款记录界面
void BTS_Mgmt::refreshLatestWithdrawInfo()
{
    QSqlDatabase sqlite_withdraw = QSqlDatabase::database("withdraw");
    QSqlQuery query_withdraw(sqlite_withdraw);
    query_withdraw.prepare("SELECT savingsamount,interest,withdrawamount,reviewstatus FROM WITHDRAW WHERE custtelNumber = ? ");
    query_withdraw.addBindValue(ui->telnumber_now->text());
    query_withdraw.exec();
    if(query_withdraw.next())
        ui->cust_latest_widraw_box->initLatestWithdrawBox(query_withdraw.value(0).toString(),query_withdraw.value(1).toString(),query_withdraw.value(2).toString(),
                                                  query_withdraw.value(3).toString());
    else
        ui->cust_latest_widraw_box->initLatestWithdrawBox("无","无","无","无");
}

//更新营业员取款审核界面
void BTS_Mgmt::refreshWithdrawApply()
{
    //更新前先删除所有已存在的信息
    // 删除所有已存在的子控件
    QLayoutItem* child;
    while ((child = ui->clerk_withdraw_apply_manage_area_layout->takeAt(0)) != nullptr)
    {
        // 删除子控件
        if (child->widget())
        {
            delete child->widget();
        }
        // 删除布局项
        delete child;
    }

    //正式更新
    ui->clerk_withdraw_apply_manage_area_layout->setAlignment(Qt::AlignTop|Qt::AlignLeft);
    QSqlDatabase sqlite_withdraw = QSqlDatabase::database("withdraw");
    QSqlQuery query_withdraw(sqlite_withdraw);
    query_withdraw.prepare("SELECT custtelnumber,savingsamount,interest,withdrawamount,reviewstatus FROM WITHDRAW WHERE clerkemployeeid = ? ");
    query_withdraw.addBindValue(ui->empleeid_now->text());
    query_withdraw.exec();
    while(query_withdraw.next())
    {
        clerk_withdraw_apply_info * info = new clerk_withdraw_apply_info(this);
        info->initWithdrawApplyInfo(query_withdraw.value(0).toString(),query_withdraw.value(1).toString(),query_withdraw.value(2).toString(),
                                   query_withdraw.value(3).toString(),query_withdraw.value(4).toString());
        ui->clerk_withdraw_apply_manage_area_layout->addWidget(info);
    }
}

//更新营业员我的账户界面
void BTS_Mgmt::refreshMyAccount()
{
    QSqlDatabase sqlite_dep = QSqlDatabase::database("deposit");
    QSqlQuery query_dep(sqlite_dep);
    query_dep.prepare("SELECT custtelnumber,custaddress,savingsamount,losttime,reviewstatus FROM DEPOSIT WHERE custtelNumber = ? ");
    query_dep.addBindValue(ui->telnumber_now->text());
    query_dep.exec();
    if(query_dep.next())
        ui->cust_my_account_box->initCustMyaccountBox(query_dep.value(0).toString(),query_dep.value(1).toString(),query_dep.value(2).toString(),
                                                  query_dep.value(3).toString(),query_dep.value(4).toString());
    else
        ui->cust_my_account_box->initCustMyaccountBox("您尚未开户","您尚未开户","您尚未开户","您尚未开户","您尚未开户");
}

//更新客户我的存款信息界面
void BTS_Mgmt::refreshMyDepositInfo()
{
    QSqlDatabase sqlite_dep = QSqlDatabase::database("deposit");
    QSqlQuery query_dep(sqlite_dep);
    query_dep.prepare("SELECT savingsamount,savingstype,savingstime,islost FROM DEPOSIT WHERE custtelNumber = ? ");
    query_dep.addBindValue(ui->telnumber_now->text());
    query_dep.exec();
    if(query_dep.next())
        ui->cust_my_deposit_box->initMyDepositInfo(query_dep.value(0).toString(),query_dep.value(1).toString(),query_dep.value(2).toString(),
                                                  query_dep.value(3).toString());
    else
        ui->cust_my_deposit_box->initMyDepositInfo("无","无","无","无");
}

//更新营业员我的客户信息界面
void BTS_Mgmt::clerkRefreshMyCustInfo()
{
    //更新前先删除所有已存在的信息
    // 删除所有已存在的子控件
    QLayoutItem* child;
    while ((child = ui->clerk_myacc_contents_layout->takeAt(0)) != nullptr)
    {
        // 删除子控件
        if (child->widget())
        {
            delete child->widget();
        }
        // 删除布局项
        delete child;
    }

    //正式更新
    ui->clerk_myacc_contents_layout->setAlignment(Qt::AlignTop|Qt::AlignLeft);
    QSqlDatabase sqlite_dep = QSqlDatabase::database("deposit");
    QSqlQuery query_dep(sqlite_dep);
    query_dep.prepare("SELECT custtelnumber,custaddress,savingsamount,losttime,reviewstatus FROM DEPOSIT WHERE clerkemployeeid = ? ");
    query_dep.addBindValue(ui->empleeid_now->text());
    query_dep.exec();
    while(query_dep.next())
    {
        cust_myaccount_showinfo* info = new cust_myaccount_showinfo(this);
        info->initCustMyaccountBox(query_dep.value(0).toString(),query_dep.value(1).toString(),query_dep.value(2).toString(),
                                   query_dep.value(3).toString(),query_dep.value(4).toString());
        ui->clerk_myacc_contents_layout->addWidget(info);
    }
}

//更新经理我的客户信息界面
void BTS_Mgmt::managerRefreshMyCustInfo()
{
    //经理不会对客户进行操作，直接再登录时更新一次即可
    //正式更新
    ui->manager_my_account_layout->setAlignment(Qt::AlignTop|Qt::AlignLeft);
    QSqlDatabase sqlite_dep = QSqlDatabase::database("deposit");
    QSqlQuery query_dep(sqlite_dep);
    query_dep.prepare("SELECT custtelnumber,custaddress,savingsamount,losttime,reviewstatus,clerkemployeeid FROM DEPOSIT ");
    query_dep.exec();
    while(query_dep.next())
    {
        manager_my_cust_info* info = new manager_my_cust_info(this);
        info->initManagerMyCustInfoBox(query_dep.value(0).toString(),query_dep.value(1).toString(),query_dep.value(2).toString(),
                                   query_dep.value(3).toString(),query_dep.value(4).toString(),query_dep.value(5).toString());
        ui->manager_my_account_layout->addWidget(info);
    }
}

//经理更新营业员信息界面
void BTS_Mgmt::managerRefreshMyClerkInfo()
{    //更新前先删除所有已存在的信息
    // 删除所有已存在的子控件
    QLayoutItem* child;
    while ((child = ui->manager_my_clerk_layout->takeAt(0)) != nullptr)
    {
        // 删除子控件
        if (child->widget())
        {
            delete child->widget();
        }
        // 删除布局项
        delete child;
    }

    //正式更新
    ui->manager_my_clerk_layout->setAlignment(Qt::AlignTop|Qt::AlignLeft);
    QSqlDatabase sqlite_acc = QSqlDatabase::database("MY");
    QSqlQuery query_acc(sqlite_acc);
    query_acc.prepare("SELECT * FROM CLERK");
    query_acc.exec();
    while(query_acc.next())
    {
        clerk_center_showinfo* info = new clerk_center_showinfo(this);
        info->initClerkSelfInfoBox(query_acc.value(1).toString(),query_acc.value(2).toString(),query_acc.value(3).toString(),
                                   query_acc.value(0).toInt());
        ui->manager_my_clerk_layout->addWidget(info);
    }

}

//初始化UI界面信息
void BTS_Mgmt::initUi()
{
    //设置窗口
    this->setWindowTitle("储蓄卡业务办理系统");
    //设置客户选项样式
    ui->cust_home->setIconAndText(":/images/cust_home.png","首页",0);
    ui->cust_center->setIconAndText(":/images/cust_center.png","个人中心",1);
    ui->cust_deposit->setIconAndText(":/images/cust_deposit.png","存款申请",2);
    ui->cust_withdrawl->setIconAndText(":/images/cust_deposit.png","取款申请",3);
    ui->cust_transaction_history->setIconAndText(":/images/cust_transaction.png","交易明细",4);

    //设置营业员选项格式
    ui->clerk_home->setIconAndText(":/images/cust_home.png","首页",0);
    ui->clerk_center->setIconAndText(":/images/cust_center.png","个人中心",1);
    ui->clerk_manage_my_cust->setIconAndText(":/customer.png","我的客户",2);
    ui->clerk_manage_withdrawl->setIconAndText(":/images/cust_deposit.png","取款管理",3);

    //设置经理选项格式
    ui->manager_cust->setIconAndText(":/customer.png","客户管理",0);
    ui->manager_clerk->setIconAndText(":/clerk.png","营业员管理",1);
    ui->manager_transaction_history->setIconAndText(":/images/cust_transaction.png","交易明细",2);
}


BTS_Mgmt::~BTS_Mgmt()
{
    delete ui;
}

//注册用户
void BTS_Mgmt::on_registered_clicked()
{
    register_dialog* reg_dialog = new register_dialog(this);
    reg_dialog->setWindowTitle("注册新用户");
    reg_dialog->show();

}

//按身份进行登录
void BTS_Mgmt::on_login_clicked()
{
    //记录当前的手机号与密码
    QString telnumber = ui->telnumber->text();
    QString password = ui->password->text();

    QSqlDatabase sqlite = QSqlDatabase::database("MY");
    QSqlQuery query(sqlite);
    if(ui->cust_bnt->isChecked())//处理客户登录
    {
        query.prepare("SELECT password FROM CUSTOMER WHERE telNumber = ? ");
        query.addBindValue(ui->telnumber->text());
        query.exec();

        if(query.next())
        {
            if(query.value(0) == ui->password->text())
            {
                //跳转到customer的首页
                ui->login_and_operator->setCurrentIndex(1);
                ui->operator_by_id->setCurrentIndex(0);
                ui->cust_page_box->setCurrentIndex(0);
                ui->telnumber_now->setText(telnumber);
                //初始化个人中心的信息
                query.prepare("SELECT username FROM CUSTOMER WHERE telNumber = ? ");
                query.addBindValue(telnumber);
                if(query.exec()) query.next();
                ui->self_info_box->initCustSelfInfoBox(query.value(0).toString(),password,telnumber);
                //初始化我的账户信息
                refreshMyAccount();
                //初始化我的存款信息
                refreshMyDepositInfo();
                //初始化最近一条取款信息界面
                refreshLatestWithdrawInfo();
                //初始化交易明细
                refreshCustTransactionDetail();
                //登录成功界面
                QMessageBox box;
                box.setWindowTitle("welcome");
                box.setText("登录成功");
                box.setIcon(QMessageBox::Information);
                box.exec();
                return;
            }
            else
            {
                //弹出密码错误信息
                QMessageBox box;
                box.setWindowTitle("warning");
                box.setText("密码错误");
                box.setIcon(QMessageBox::Warning);
                box.exec();
                return;
            }
            return;
        }
        else
        {
            QMessageBox box;
            box.setWindowTitle("warning");
            box.setText("当前手机号未注册");
            box.setIcon(QMessageBox::Warning);
            box.exec();
            return;
        }
    }
    else if(ui->clerk_bnt->isChecked())//处理营业员登录
    {
        query.prepare("SELECT password FROM CLERK WHERE telNumber = ? ");
        query.addBindValue(ui->telnumber->text());
        query.exec();

        if(query.next())
        {
            if(query.value(0) == ui->password->text())
            {
                //跳转到clerk的首页
                ui->login_and_operator->setCurrentIndex(1);
                ui->operator_by_id->setCurrentIndex(1);
                ui->clerk_page_box->setCurrentIndex(0);
                //初始化个人中心的信息
                query.prepare("SELECT employeeId,username FROM CLERK WHERE telNumber = ? ");
                query.addBindValue(telnumber);
                if(query.exec()) query.next();
                ui->self_info_box_2->initClerkSelfInfoBox(query.value(1).toString(),password,telnumber,query.value(0).toInt());
                ui->empleeid_now->setText(query.value(0).toString());
                //初始化我的客户信息
                clerkRefreshMyCustInfo();
                //初始化取款审核界面
                refreshWithdrawApply();
                //登录成功界面
                QMessageBox box;
                box.setWindowTitle("welcome");
                box.setText("登录成功");
                box.setIcon(QMessageBox::Information);
                box.exec();
                return;
            }
            else
            {
                //弹出密码错误信息
                QMessageBox box;
                box.setWindowTitle("warning");
                box.setText("密码错误");
                box.setIcon(QMessageBox::Warning);
                box.exec();
                return;
            }
            return;
        }
        else
        {
            QMessageBox box;
            box.setWindowTitle("warning");
            box.setText("当前手机号未注册");
            box.setIcon(QMessageBox::Warning);
            box.exec();
            return;
        }
    }
    else if(ui->mng_bnt->isChecked())//处理经理登录
    {
        query.prepare("SELECT password FROM MANAGER WHERE telNumber = ? ");
        query.addBindValue(ui->telnumber->text());
        query.exec();

        if(query.next())
        {
            if(query.value(0) == ui->password->text())
            {
                //跳转到manager的首页
                ui->login_and_operator->setCurrentIndex(1);
                ui->operator_by_id->setCurrentIndex(2);
                ui->manager_page_box->setCurrentIndex(0);
                //初始化我的客户界面
                managerRefreshMyCustInfo();
                //初始化营业员信息
                managerRefreshMyClerkInfo();
                //初始化交易明细信息
                refreshManagerTransactionDetail();
                //初始化到期储金
                initManagerCustFinishMoney();
                //登录成功界面
                QMessageBox box;
                box.setWindowTitle("welcome");
                box.setText("登录成功");
                box.setIcon(QMessageBox::Information);
                box.exec();
                return;
            }
            else
            {
                //弹出密码错误信息
                QMessageBox box;
                box.setWindowTitle("warning");
                box.setText("密码错误");
                box.setIcon(QMessageBox::Warning);
                box.exec();
                return;
            }
            return;
        }
        else
        {
            QMessageBox box;
            box.setWindowTitle("warning");
            box.setText("当前手机号未注册");
            box.setIcon(QMessageBox::Warning);
            box.exec();
            return;
        }
    }
    return;
}

//客户退出登录
void BTS_Mgmt::on_cust_exit_log_clicked()
{
    ui->login_and_operator->setCurrentIndex(0);
}

//营业员退出登录
void BTS_Mgmt::on_clerk_exit_log_clicked()
{
    ui->login_and_operator->setCurrentIndex(0);
}

//经理退出登录
void BTS_Mgmt::on_manager_exit_log_clicked()
{
    ui->login_and_operator->setCurrentIndex(0);
}

//客户开户申请
void BTS_Mgmt::on_acc_open_apply_clicked()
{
    acc_open_dialog* dialog = new acc_open_dialog(this);
    dialog->telNumberNow = ui->telnumber_now->text();
    dialog->exec();
    refreshMyAccount();
    //QSqlDatabase sqlite = QSqlDatabase::database("deposit");
    //QSqlQuery query(sqlite);
}

//营业员开户审核
void BTS_Mgmt::on_clerk_acc_open_review_clicked()
{
    clerk_review_acc_open dialog;
    dialog.exec();
    clerkRefreshMyCustInfo();
}

//用户申请存款
void BTS_Mgmt::on_cust_apply_deposit_clicked()
{
    cust_apply_deposit_dialog dialog;
    dialog.exec();
    refreshMyAccount();
    refreshMyDepositInfo();
    refreshCustTransactionDetail();
}

//用户申请取款
void BTS_Mgmt::on_cust_apply_withdraw_clicked()
{
    cust_apply_withdraw_dialog dialog;
    dialog.exec();
    refreshLatestWithdrawInfo();
    refreshCustTransactionDetail();
}

//用户申请挂失
void BTS_Mgmt::on_acc_lost_apply_clicked()
{
    cust_acc_lost_apply dialog;
    dialog.exec();
    refreshMyAccount();
    refreshMyDepositInfo();
}

//营业员取款审核
void BTS_Mgmt::on_clerk_withdraw_apply_manage_bnt_clicked()
{
    clerk_manage_withdraw_apply_dialog dialog;
    dialog.exec();
    clerkRefreshMyCustInfo();
    refreshWithdrawApply();
}

//经理新增营业员
void BTS_Mgmt::on_manager_add_clerk_bnt_clicked()
{
    manager_add_clerk_dialog dialog;
    dialog.exec();
    managerRefreshMyClerkInfo();
}
